﻿using System;
using Token.Piker.Common;
using System.IO;

namespace Token.Piker.Web.Admin.Slide
{
    public partial class Add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Session[GlobalConstants.PIKER_ADMIN] == null)
            {
                MessageBox.ShowAndRedirect(this.Page, "网络连接超时，请重新登录！", ResolveClientUrl("~/Admin/Login.aspx"));
                return;
            }

            if (!uploadSlide.HasFile)
            {
                MessageBox.Show(this.Page, "请选择首页图！");
                return;
            }
            string URL = this.txtURL.Text;
            int Adder = Convert.ToInt32(Session[GlobalConstants.PIKER_ADMIN]);
            DateTime AddTime = DateTime.Now;
            int SlideState = 0;
            string path = "~/Admin/uploads/slide/";
            string fileName = uploadSlide.FileName;
            fileName = Path.GetExtension(fileName);
            string SRC = path + DateTime.Now.ToString("yyyyMMddhhmmss") + fileName;
            uploadSlide.SaveAs(Server.MapPath(SRC));

            Token.Piker.Model.Slide model = new Token.Piker.Model.Slide();
            model.URL = URL;
            model.SRC = SRC;
            model.Adder = Adder;
            model.AddTime = AddTime;
            model.SlideState = SlideState;

            Token.Piker.BLL.SlideBLL bll = new Token.Piker.BLL.SlideBLL();
            bll.Add(model);
            MessageBox.ShowAndRedirect(this, "保存成功！", "Add.aspx");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}